package com.ds.maker.generator.file;

import com.ds.maker.model.DataModel;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

/**
 * 静态喝动态文件生成汇总
 */
public class FileGenerator {
    public static void main(String[] args) throws TemplateException, IOException {
        //静态文件生成
//        String projectPath = System.getProperty("user.dir");//获取到这个项目的根目录
//        File parentFile = new File(projectPath).getParentFile();
//        //输入路径
////        String inputPath = projectPath + File.separator + "ds-generator-demo-projects"+ File.separator+"acm-template";
//        String inputPath = new File(parentFile,"ds-generator-demo-projects/acm-template").getAbsolutePath();
//        //输出路径
//        String outputPath = projectPath;
//        StaticGenerator.copyFilesByHutool(inputPath, outputPath);
//
//        //动态文件生成
////        String dynamicprojectPath = System.getProperty("user.dir") + File.separator +"ds-generator-basic";
//        String dynamicinputPath = projectPath + File.separator + "src/main/resources/templates/MainTemplate.java.ftl";
//        String dynamicoutputPath = outputPath + File.separator + "acm-template/src/com/ds/acm/MainTemplate.java";

        DataModel dataModel = new DataModel();
        dataModel.setAuthor("ds");
        dataModel.setLoop(false);
        dataModel.setOutputText("求和结果：");

        doGenerate(dataModel);
    }


    public static void doGenerate(Object model) throws IOException, freemarker.template.TemplateException {
        //静态文件生成
        String projectPath = System.getProperty("user.dir");//获取到这个项目的根目录
        File parentFile = new File(projectPath).getParentFile();
        //输入路径
//        String inputPath = projectPath + File.separator + "ds-generator-demo-projects"+ File.separator+"acm-template";
        String inputPath = new File(parentFile,"ds-generator-demo-projects/acm-template").getAbsolutePath();
        //输出路径
        String outputPath = projectPath;
        StaticFileGenerator.copyFilesByHutool(inputPath, outputPath);

        //动态文件生成
//        String dynamicprojectPath = System.getProperty("user.dir") + File.separator +"ds-generator-basic";
        String dynamicinputPath = projectPath + File.separator + "src/main/resources/templates/MainTemplate.java.ftl";
        String dynamicoutputPath = outputPath + File.separator + "acm-template/src/com/ds/acm/MainTemplate.java";



        DynamicFileGenerator.doGenerate(dynamicinputPath, dynamicoutputPath, model);
    }


}
